<html>
<head><meta charset="utf-8"><title>filter_next lint · clippy · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/index.html">clippy</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/filter_next.20lint.html">filter_next lint</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="213135379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/filter_next%20lint/near/213135379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ThibsG <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/filter_next.20lint.html#213135379">(Oct 13 2020 at 10:26)</a>:</h4>
<p>Hello!<br>
I triggered <code>filter_next</code> lint in my work project:</p>
<div class="codehilite"><pre><span></span><code>error: called `filter(p).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(p)` instead.
    |
197 | ...                   (&amp;**path).split(&#39;/&#39;).filter(|&amp;p| !p.is_empty()).next()
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `-D clippy::filter-next` implied by `-D warnings`
    = note: replace `filter(|&amp;p| !p.is_empty()).next()` with `find(|&amp;p| !p.is_empty())`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#filter_next
</code></pre></div>


<p>As you can see, the error message (first line) is a bit misleading in this case, due to the name <code>p</code> of the <code>filter</code> closure's variable  <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span><br>
I didn't notice at first glance the replacement note at the bottom.<br>
Maybe these are bad ideas, but we could:</p>
<ul>
<li>replace <code>p</code> on the first line with something like <code>&lt;p&gt;</code> or <code>&lt;predicate&gt;</code></li>
<li>move the replacement note around the problematic code, to be more visible</li>
</ul>
<p><a href="https://github.com/rust-lang/rust-clippy/blob/febd0086a5ea6475d8243c7651908ddd96711896/clippy_lints/src/methods/mod.rs#L2851">Lint code is right here</a></p>



<a name="213136813"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/filter_next%20lint/near/213136813" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/filter_next.20lint.html#213136813">(Oct 13 2020 at 10:43)</a>:</h4>
<p>I like both ideas. The second can be done, by moving from <code>span_lint_and_note</code> to <code>span_lint_and_sugg</code></p>



<a name="213159548"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/filter_next%20lint/near/213159548" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eduardo Broto <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/filter_next.20lint.html#213159548">(Oct 13 2020 at 14:09)</a>:</h4>
<p>In the codebase I think we use "_" and ".." for placeholders, with some preference for the latter it seems.</p>
<p>BTW there are other uses of a single letter in the same module, maybe it would make sense to change them all at once.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>